<?php

namespace app\common\model;

use think\Db;
use think\Model;


class TeamSaleItem extends Model
{

    

    

    // 表名
    protected $name = 'team_sale_item';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
	
	public function plan() {
		return $this->belongsTo('businessPlan', 'business_plan_id', 'id', '', 'left')->setEagerlyType(0);
	}
	
	public function team() {
		return $this->belongsTo('team', 'team_id', 'id', '', 'left')->setEagerlyType(0);
	}
	
	public function user() {
		return $this->belongsTo('user', 'user_id', 'id', '', 'left')->setEagerlyType(0);
	}
	
	/**
	 * 添加大赛销售详情
	 * @param $planId
	 * @param $teamId
	 * @param $userId
	 * @param $number
	 * @param $orderId
	 * @return int|string
	 */
	public function addNumber($planId, $teamId, $userId, $number, $orderId) {
		return Db::name('teamSaleItem')
			->insert([
				'business_plan_id' => $planId,
				'team_id' => $teamId,
				'user_id' => $userId,
				'number' => $number,
				'order_id' => $orderId,
			]);
	}





}
